home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Format / asn / asn_enc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.8 KB  |  120 lines

  1. /* asn_enc.c - encode ASN after body part conversion */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Format/asn/RCS/asn_enc.c,v 6.0 1991/12/18 20:15:43 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Format/asn/RCS/asn_enc.c,v 6.0 1991/12/18 20:15:43 jpo Rel $
  9.  *
  10.  * $Log: asn_enc.c,v $
  11.  * Revision 6.0  1991/12/18  20:15:43  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include    "head.h"
  19. #include    "asn.h"
  20.  
  21.  
  22.  
  23.  
  24. /* ------------------------  Start Routine  --------------------------------- */
  25.  
  26.  
  27.  
  28.  
  29. asn_encode(func_encode, data)
  30. int    (*func_encode) ();
  31. ASNBODY    *data;
  32. {
  33.     PE    pe;
  34.  
  35.     PP_TRACE (("asn_encode()"));
  36.  
  37.     /* --- *** ---
  38.     write body part in plain or wrapped mode.
  39.     if ffunc is set then wrapped.
  40.     --- *** --- */
  41.  
  42.  
  43.     if (func_encode == NULL) {
  44.         wr_stdout (data);
  45.         return;
  46.     }
  47.     
  48.  
  49.     /* -- call encoder function -- */
  50.     (*func_encode)(&pe, data);
  51.  
  52.     asn_wr_stdout (pe);
  53.     pe_free(pe);
  54. }
  55.  
  56.  
  57.  
  58.  
  59. /* ------------------------  Static Routines  ------------------------------- */
  60.  
  61.  
  62.  
  63.  
  64. static asn_wr_stdout(pe)
  65. PE    pe;
  66. {
  67.     register PS    ps;
  68.  
  69.  
  70.     PP_TRACE (("asn_wr_stdout(%x)", pe));
  71.  
  72.     if (pe == NULLPE) {
  73.         PP_LOG(LLOG_EXCEPTIONS, ("pe is null"));
  74.         exit (1);
  75.     }
  76.  
  77.     if ((ps = ps_alloc(std_open)) == NULLPS) {
  78.         PP_LOG(LLOG_EXCEPTIONS, ("ps_alloc(stdout) error"));
  79.         exit (1);
  80.     }
  81.  
  82.     if (std_setup(ps, stdout) == NOTOK) {
  83.         PP_LOG(LLOG_EXCEPTIONS, ("std_setup(stdout) error"));    
  84.         exit (1);
  85.     }
  86.  
  87.     (void) ps_get_abs(pe);
  88.  
  89.     if (pe2ps(ps, pe) == NOTOK) {
  90.         if (ps->ps_errno)
  91.             PP_LOG(LLOG_EXCEPTIONS,
  92.                 ("ps2pe: %s", ps_error(ps->ps_errno)));
  93.         else 
  94.             PP_LOG(LLOG_EXCEPTIONS, ("ps2pe error"));
  95.         exit (1);
  96.     }
  97.  
  98.     ps_free(ps);
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105. static wr_stdout (data)
  106. ASNBODY    *data; 
  107. {
  108.     ASNBODY    *dp;
  109.     int    n;
  110.     char    *c;
  111.  
  112.     PP_TRACE (("wr_stdout()"));
  113.  
  114.     for (dp = data; dp; dp = dp -> next)
  115.         for (n = dp -> length, c = dp -> line; n > 0; n--, c++) 
  116.             putchar (*c);
  117.             
  118.     fflush (stdout);
  119. }
  120.